package com.oocl.invoker;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.oocl.invoker.client.ChartService;
import com.oocl.invoker.client.MemberService;
import com.oocl.invoker.entity.Goods;

@RestController
public class InvokerController {

	@Autowired
	private MemberService memberService;
	
	@Autowired
	private ChartService chartService;
	
	@RequestMapping(value="/memeber/{id}")
    public Member getMemeberById(@PathVariable("id") Integer id){
    	return memberService.findMemberById(id);
    }
	
	@RequestMapping(value="/add",produces = MediaType.APPLICATION_JSON_VALUE)
	public Record addGoodsByMemeberIdAndGoodsId(@RequestParam("memberId") Integer m_id,@RequestParam("goods_id") Integer g_id){
		Member member=memberService.findMemberById(m_id);
		Goods goods=chartService.addOneGoodsInChart(g_id);
		Record record=new Record();
		record.setMember(member);
		record.getGoods().add(goods);
		return record;
	}
	
	
	
}
